package com.xz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xz.R;
import com.xz.client.VideoClient;
import com.xz.entity.Video;
import com.xz.entity.Vplayer;
import com.xz.entity.frontvo.VideoPlayerVo;
import com.xz.mapper.VplayerMapper;
import com.xz.service.VideoService;
import com.xz.service.VplayerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-08-09
 */
@Service
public class VplayerServiceImpl extends ServiceImpl<VplayerMapper, Vplayer> implements VplayerService {
    @Autowired
    private VideoService videoService;
    @Autowired
    private VideoClient videoClient;
    @Override
    public VideoPlayerVo getPlayerOne(String videoId) {
        VideoPlayerVo videoPlayerVo=new VideoPlayerVo();
        Video video = videoService.getById(videoId);
        BeanUtils.copyProperties(video,videoPlayerVo);
//        videoPlayerVo.setPrice(video.getPrice());
//        videoPlayerVo.setCover(video.getCover());
//        videoPlayerVo.setTitle(video.getTitle());
//        videoPlayerVo.setDescription(video.getDescription());
        QueryWrapper<Vplayer> wrapper=new QueryWrapper<>();
        wrapper.eq("video_id",videoId);
        Vplayer vplayer = this.baseMapper.selectOne(wrapper);
        videoPlayerVo.setVid(vplayer.getVideoSourceId());
        //远程获取凭证
        String PlayAuth = videoClient.getPlayAuth(vplayer.getVideoSourceId());
        String path=videoClient.getPlayUrl(vplayer.getVideoSourceId());
        videoPlayerVo.setPlayAuth(PlayAuth);
        videoPlayerVo.setPath(path);
        return videoPlayerVo;
    }
}
